package com.zhangxin.threadcoreknowledge.threadobjectclasscommonmethods;

/**
 * 演示: 线程sleep的时候,不释放synchronized 的monitor, 等sleep()时间到了之后,正常结束之后才释放
 */
public class Demo07SleepDontReleaseMonitor implements Runnable{

    public static void main(String[] args) {
        Demo07SleepDontReleaseMonitor sleepDontReleaseMonitor = new Demo07SleepDontReleaseMonitor();
        new Thread(sleepDontReleaseMonitor).start();
        new Thread(sleepDontReleaseMonitor).start();
    }

    @Override
    public void run() {
        syn();
    }

    private synchronized void syn() {
        System.out.println("Thread:" + Thread.currentThread().getName() + " got monitor");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Thread: " + Thread.currentThread().getName() + " released monitor");

    }
}
